<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>

</head>
<body>
<div style="text-align: center">
    <from>
        账号：<input type="text" id="name" placeholder="请输入账号"><br>
        密码：<input type="pwd" id="pwd" placeholder="请输入密码"><br>
        <input type="submit" value="登录" style="text-align: center;margin-top: 10px" id="but">
        <input type="button" value="注册" style="text-align: center;margin-top: 10px" id="insert">
    </from>
</div>
</body>
<script>
    $("#but").click(function(event) {
        // 获取输入框数据
        var name = $('#name').val();
        var password = $('#pwd').val();
        var jsonData = { // 封装接口数据
            "name": name,
            "pwd": password //要和后端的名字相对应
        }

        login(jsonData);
    })

    $("#insert").click(function () {
        window.location.href="insert";
    })


    /**
     * 请求接口
     */
    function login(jsonData) {
        $.ajax({
            type: "GET",
            url: "http://localhost:8888/login11",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
            },
            data: jsonData,
            dataType: "json",
            success: function(data){
                if (data.code == 200) {
                    alert(data.msg);
                    window.location.href = "home";
                } else {
                    alert(data.msg);
                }
            }
        });
    }
</script>
</html>